﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.AspNetCore.Mvc.Authorization;
using Abp.Auditing;
using AbpZeroTemplate.Authorization.Users;
using AbpZeroTemplate.Authorization.Users.Dto;
using AbpZeroTemplate.Web.Controllers;
using AbpZeroTemplate.Web.Swagger;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace AbpZeroTemplate.Api.Admin.Controllers
{
    /// <summary>用户链接
    /// </summary>
    [Area("Admin")]
    [Route("Admin/UserLink/[action]")]
    [ApiName("Admin")]
    [RemoteService]
    [AbpMvcAuthorize]
    public class UserLinkController : AbpZeroTemplateControllerBase
    {
        private readonly IUserLinkAppService _userLinkAppService;
        /// <summary>ctor
        /// </summary>
        public UserLinkController(IUserLinkAppService userLinkAppService)
        {
            _userLinkAppService = userLinkAppService;
        }

        /// <summary>添加链接
        /// </summary>
        [HttpPost]
        public async Task LinkToUser([FromBody]LinkToUserInput input)
        {
            await _userLinkAppService.LinkToUser(input);
        }

        /// <summary>获取链接的用户
        /// </summary>
        [HttpGet]
        public async Task<PagedResultDto<LinkedUserDto>> GetLinkedUsers(GetLinkedUsersInput input)
        {
            return await _userLinkAppService.GetLinkedUsers(input);
        }


        /// <summary>获取最近添加的友好用户
        /// </summary>
        [HttpGet]
        [DisableAuditing]
        public async Task<ListResultDto<LinkedUserDto>> GetRecentlyUsedLinkedUsers()
        {
            return await _userLinkAppService.GetRecentlyUsedLinkedUsers();
        }

        /// <summary>取消链接
        /// </summary>
        [HttpGet]
        public async Task UnlinkUser(UnlinkUserInput input)
        {
            await _userLinkAppService.UnlinkUser(input);
        }
    }
}
